home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 4858 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.0 KB  |  38 lines

  1. Path: lk-hp-10.hut.fi!casper
  2. From: casper@lk-hp-10.hut.fi (Casper Gripenberg)
  3. Newsgroups: comp.lang.c++
  4. Subject: Is it possible to use templates with structures?
  5. Date: 1 Feb 1996 11:57:57 GMT
  6. Organization: Helsinki University of Technology
  7. Distribution: inet
  8. Message-ID: <4eq9s5$l14@nntp.hut.fi>
  9. NNTP-Posting-Host: lk-hp-10.hut.fi
  10.  
  11.  
  12.  
  13. Can I do:
  14.  
  15. template<class T>
  16. struct Foo {
  17.   T *data;
  18. };
  19.  
  20. ??
  21.  
  22. The compiler doesn't seem to complain but I would still like to be
  23. sure if it's ok to do it. 
  24.  
  25. The reason I want to do it is that I need to allocate the structure
  26. with my own allocation routine and not with new. Also I can't override
  27. new in the class so that won't work either. While on the same subject
  28. could I have a template class dontaining just data members and
  29. no constructors/destructor or memberfunctions and then allocate
  30. it without using new? As I understand it the only thing new does
  31. that for example malloc doesn't do is run the constructor code. So
  32. is it safe to use that kind of a template class allocated with malloc??
  33.  
  34. Thanks...
  35.  
  36. // Casper
  37.  
  38.